
#include "Render/TileRenderer.hpp"

TileRenderer::TileRenderer( const boost::shared_ptr< Tile > & tilePtr ) 
                          : mTilePtr( tilePtr )
{
}

void TileRenderer::Render()
{
     GLfloat red = static_cast< GLfloat >( GetRValue( mTilePtr->GetColor() ) );
     GLfloat green = static_cast< GLfloat >( GetGValue( mTilePtr->GetColor() ) );
     GLfloat blue = static_cast< GLfloat >( GetBValue( mTilePtr->GetColor() ) );
     
     glColor3f( red, green, blue );

     GLfloat tileX = static_cast< GLfloat >( mTilePtr->GetLocation().GetX() );
     GLfloat tileY = static_cast< GLfloat >( mTilePtr->GetLocation().GetY() );
     GLfloat tileZ = static_cast< GLfloat >( mTilePtr->GetLocation().GetZ() );

	glBegin(GL_TRIANGLES); // top left
		glVertex3f( tileX, tileY, 0.0 ); // top left
		glVertex3f( tileX + TILE_WIDTH, tileY, 0.0 ); // top right
		glVertex3f( tileX, tileY + TILE_HEIGHT, 0.0 ); // bottom left
	glEnd();
	glBegin(GL_TRIANGLES); // bottom right
		glVertex3f( tileX + TILE_WIDTH, tileY, 0.0 ); // top right
		glVertex3f( tileX, tileY + TILE_HEIGHT, 0.0 ); // bottom left
		glVertex3f( tileX + TILE_WIDTH, tileY + TILE_HEIGHT, 0.0 ); // bottom right
	glEnd();
}